import React from 'react';
import { Menu, Icon } from 'antd';
import styles from './Sider.css';
import {NEWS_PAGE_SIZE} from '../../constants'

function SideBar({ location, params, weixin, dispatch}) {
  // console.log('Sider params', params);

  return (
    <Menu
      className={styles.menu}
      selectedKeys={[weixin.showModule]}
      theme="light"
      onSelect={handleMenuSelect}
    >
      <Menu.Item key="news">
        <Icon type="bars" />图文管理
      </Menu.Item>
      <Menu.Item key="users">
        <Icon type="bars" />用户管理
      </Menu.Item>
    </Menu>
  );

  function handleMenuSelect({item, key, selectedKeys}) {
    // console.log('mmm')
    // console.log(item, key, selectedKeys)
    dispatch({type: 'weixin/selectSideMenu', key: key});
    //点击菜单时，加载数据
    if (key == 'news') {
      dispatch({ type: 'weixin/fetchNews', payload: {page: 0, pageSize: NEWS_PAGE_SIZE} });
    }
    if (key == 'users') {
      //点击菜单时，加载数据
      dispatch({type: 'weixin/getUsers', payload: {nextOpenid: ''}});
    }
  }
}



SideBar.contextTypes = {
  router: React.PropTypes.object
}

export default SideBar;
